/**
 * 抑制开发环境中的特定警告
 */

const isDev = process.env.NODE_ENV === 'development';

if (isDev) {
  // 保存原始的 console 方法
  const originalConsoleWarn = console.warn;
  const originalConsoleError = console.error;

  // 需要抑制的警告模式
  const suppressedWarnings = [
    'findDOMNode is deprecated',
    'Warning: findDOMNode is deprecated and will be removed in the next major release',
    'Static function can not consume context like dynamic theme',
    '[antd: Modal] Static function can not consume context',
    '[antd: message] Static function can not consume context',
    '[antd: Card] `bodyStyle` is deprecated',
    '[antd: Card] `bordered` is deprecated',
    '[React Intl] Missing message:',
  ];

  // 重写 console.warn
  console.warn = (...args) => {
    const message = args.join(' ');
    const shouldSuppress = suppressedWarnings.some((pattern) => message.includes(pattern));

    if (!shouldSuppress) {
      originalConsoleWarn.apply(console, args);
    }
  };

  // 重写 console.error (某些情况下警告可能以 error 形式输出)
  console.error = (...args) => {
    const message = args.join(' ');
    const shouldSuppress = suppressedWarnings.some((pattern) => message.includes(pattern));

    if (!shouldSuppress) {
      originalConsoleError.apply(console, args);
    }
  };
}

export {};
